﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FanPages.Common;
using FanPages.Server.Services.Contracts.Dto;
using FanPages.Model;

namespace FanPages.Client.Core.Transformers
{
    public class SearchResultTransformer : ITransformer<SearchResult, SearchResultDto> 
    {

        public SearchResultDto ToDto(SearchResult clientEntity)
        {
            SearchResultDto dto = new SearchResultDto()
            {
                Snippet = clientEntity.Snippet.ToString(),
                ResultDate = clientEntity.ResultDate,
                Name = clientEntity.Name,
                Link = clientEntity.Link,
                HtmlTile = clientEntity.HtmlTile,
                HtmlSnippet = clientEntity.HtmlSnippet.ToString(),
                FanItemDto = new FanItemTransformer().ToDto(clientEntity.FanItem),
                DisplayLink = clientEntity.DisplayLink,
                CachedId = clientEntity.CachedId
            };
            return dto;
        }

        public SearchResult ToClient(SearchResultDto dtoEntity)
        {
            SearchResult entity = new SearchResult()
            {
                CachedId = dtoEntity.CachedId,
                DisplayLink = dtoEntity.DisplayLink,
                FanItem = new FanItemTransformer().ToClient(dtoEntity.FanItemDto),
                HtmlSnippet = dtoEntity.HtmlSnippet,
                HtmlTile = dtoEntity.HtmlTile,
                Id = dtoEntity.Id,
                Link = dtoEntity.Link,
                Name = dtoEntity.Name,
                Snippet = dtoEntity.Snippet
            };
            return entity;
        }


        public List<SearchResultDto> ToListDto(List<SearchResult> list)
        {
            throw new NotImplementedException();
        }

        public List<SearchResult> ToListEntity(List<SearchResultDto> list)
        {
            List<SearchResult> newList = new List<SearchResult>();
            foreach (var item in list)
            {
                newList.Add(ToClient(item));
            }

            return newList;
        }
    }
}
